/*
https://leetcode-cn.com/problems/rectangle-area/solution/ju-xing-mian-ji-by-leetcode-solution-xzbl/
 */
public class Solution223 {
    public int overlap(int x1,int x2,int y1,int y2){
        if (x1>y1){
            int t=x1;x1=y1;y1=t;
            t=x2;x2=y2;y2=t;
        }
        if (x2<=y1) return 0;
        if (y2<=x2) return y2-y1;
        return x2-y1;
    }
    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int over=overlap(ax1,ax2,bx1,bx2)*overlap(ay1,ay2,by1,by2);
        return (ax2-ax1)*(ay2-ay1)+(bx2-bx1)*(by2-by1)-over;
    }

    public static void main(String[] args) {
        System.out.println(new Solution223().computeArea(-2,-2,2,2,-2,-2,2,2));
    }
}
